<template>
  <div class="user-info">
    <div class="user-detail">
        <div class="user-type" :class="roleType"><div class="text">{{roleName||'未知'}}</div></div>
        <div class="user-name">{{passport}}</div>
        <a class="logout" :href="logoutUrl">退出</a>
    </div>
  </div>
</template>

<script>
import {fetch} from '../utils/api.js';
import login from '../utils/login.js';

export default {
  name: 'UserInfo',
  props: ['userStatus'],
  data() {
    return {
      info: {},
      reloadUnreadMsgTimer: null,
      statusType: {
        1: '正常',
        0: '封禁'
      },
      roleType:{
        1:'专栏作者',
        0:'其他'
      }
    }
  },
  computed: {
    passport() {
      if (this.$store.state.user.status === 1){
        return login.userInfo.mail;
      } else if(this.$store.state.user.status === 0) {
        return this.statusType[this.$store.state.user.status] || '未知';
      } else {
        return '未知';
      }
    },
    roleName() {
      return this.roleType[this.$store.state.user.role] || '未知';

    },
    logoutUrl() {
      return `http://reg.163.com/Logout.jsp?url=${location.origin}/login.html`
    }
  }
};
</script>

<style lang="less">
.user-info {
  height: 50px;
  white-space: nowrap;
  position: absolute;
  right: 0;
  top: 30px;
  .user-mail {
    float: left;
    position: relative;
    height: 50px;
    width: 50px;
    margin-right: 22px;
    background: url("../assets/user_mail.png") center no-repeat;
    background-size: contain;
    .unread-num {
      position: absolute;
      top: 0;
      right: -2px;
      height: 15px;
      padding: 0 4px;
      border-radius: 15px;
      background: #c1252e;
      color: #fff;
      font-size: 12px;
      line-height: 15px;
      text-align: center;
      animation: unread 6s ease infinite;
    }
    @keyframes unread {
      0% {
        background: #c1252e;
      }
      5% {
        background: rgba(255, 86, 88, 0.91);
        box-shadow: 0 0 10px 3px rgba(255, 86, 88, 0.5);
      }
      10% {
        background: rgba(255, 40, 51, 0.91);
        box-shadow: 0 0 10px 3px rgba(255, 38, 47, 0.5);
      }
      100% {
        background: #c1252e;
      }
    }
  }
  .user-avatar {
    float: left;
    height: 50px;
    width: 50px;
    margin-right: 10px;
    overflow: hidden;
    border-radius: 100%;
    background: #eee;
    img {
      display: block;
      height: 100%;
      margin: 0 auto;
    }
  }
  .user-detail {
    display: inline-block;
    vertical-align: top;
  }
  .user-type {
    float: left;
    height: 20px;
    margin-top: 5px;
    margin-bottom: 10px;
    padding: 0 .5em;
    border-radius: 5px;
    background: #666;
    color: #fff;
    font-size: 12px;
    line-height: 20px;
  }
  .user-name {
    float: left;
    clear: left;
    padding-right: .5em;
    border-right: 1px solid;
    color: #666;
    font-size: 12px;
    line-height: 1em;
  }
  .logout {
    float: left;
    padding-left: .5em;
    color: #2e9057;
    font-size: 12px;
    line-height: 1em;
    cursor: pointer;
  }
}
</style>